package chixing.day17.work;

import java.util.HashMap;
import java.util.Map;

public class ProductManager {
    //创建一个Map集合，用于存储商品信息 proId作为键
    static Map<Integer,Product> productMap = new HashMap<>();
    //完成入库操作 即增加库存
    public Product addStock(Product product){
        productMap.put(product.getProId(),product);
        return product;
    }
    //完成出库（减少库存，若库存不足则提示失败）
    public Product removeStock(Product product) {

        Product product1 = productMap.get(product.getProId());
        if (product1.getProStock() > product.getProStock()) {
            product1.setProStock(product1.getProStock() - product.getProStock());
            return product1;
        } else {
            System.out.println("库存不足");
            return null;
        }
    }

    public static void main(String[] args) {
        ProductManager productManager = new ProductManager();
        Product product = new Product(1, "手机", "华为", 100);
        Product product1 = productManager.addStock(product);
        System.out.println(productMap);
        Product producta = new Product(1, "手机", "华为", 99);
        Product product2 = productManager.removeStock(producta);
        System.out.println(productMap);
        productManager.removeStock(product);
        System.out.println(productMap);
    }
}
